import api from '../../../api/index'

Page({
    data: {
        userAnswerList: [],
        userInfo: [],
        pm: null,
        score: null,
        avatarUrl:null
    },
    onLoad() {
        this.getAnswerList()
    },
    onShow() {
        this.getAnswerList()
    },
    async getAnswerList() {
        let list = [
            //     {
            //     userIndex: 1,
            //     avatarUrl: userInfo.avatarUrl,
            //     nickName: userInfo.nickName,
            //     answerIntegral: 1200
            // }, {
            //     userIndex: 2,
            //     avatarUrl: userInfo.avatarUrl,
            //     nickName: userInfo.nickName,
            //     answerIntegral: 700
            // }, {
            //     userIndex: 3,
            //     avatarUrl: userInfo.avatarUrl,
            //     nickName: userInfo.nickName,
            //     answerIntegral: 500
            // }, {
            //     userIndex: 4,
            //     avatarUrl: userInfo.avatarUrl,
            //     nickName: userInfo.nickName,
            //     answerIntegral: 300
            // }
        ]
        let than = this
        // await api.getRank().then(res => {
        //     console.log(res.data.rows);
        //     list = res.data.rows
        // })
        wx.request({
            url: 'http://localhost:8080/api/rank/list',
            method: 'GET',
            success(res) {
                let userInfo = wx.getStorageSync('mini-userInfo')
                list = res.data
               let index = res.data.findIndex((item) => {
                    return item.nickName == userInfo.nickName
                })
                wx.showLoading({
                    title: '获取信息',
                })

                setTimeout(() => {
                    wx.hideLoading()
                    than.setData({
                        userAnswerList: list,
                        userInfo: userInfo,
                        pm:index+1,
                        score:list[index].answerIntegral,
                        avatarUrl:list[index].avatarUrl,
                    })
                }, 500);
            }
        })

    }
})